package org.bluedream.core.module.service.depItem;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.commons.collections.map.HashedMap;
import org.bluedream.comm.base.BaseServiceImpl;
import org.bluedream.comm.utils.EmptyUtil;
import org.bluedream.core.module.dao.depItem.DepItemUserDao;
import org.bluedream.core.module.entity.depItem.DepItemUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
import java.util.Map;

/**
 * @ClassName depItemUserUserService
 * @Description TODO
 * @Author Administrator
 * @Data 2022/5/26 13:24
 * @Version
 */
@Service
@DS("master")
@Transactional(
        readOnly = true
)
public class DepItemUserService extends BaseServiceImpl<DepItemUserDao, DepItemUser> implements IService<DepItemUser> {
    private static final Logger logger = LoggerFactory.getLogger(DepItemUserService.class);

    @Override
    public DepItemUser getById(Serializable id) {
        if (EmptyUtil.isEmpty(id)){
            return new DepItemUser();
        }
        return super.getById(id);
    }

    public IPage<DepItemUser> findPage(DepItemUser entity , String... args){
        Map<String , Object> search = new HashedMap();
        if (EmptyUtil.isNoEmpty(entity.getDepCode())
            || EmptyUtil.isNoEmpty(entity.getLoginCode())
        ){
            if (EmptyUtil.isNoEmpty(entity.getDepCode())){
                search.put("depCode" , entity.getDepCode());
            }
            if (EmptyUtil.isNoEmpty(entity.getLoginCode())){
                search.put("loginCode" , entity.getLoginCode());
            }
        }else {
            long limit = entity.getLimit();
            long page = entity.getPage();
            entity = new DepItemUser();
            entity.setLimit(limit);
            entity.setPage(page);
        }

        return super.findPage(entity , search , args);
    }
}